import { defineComponent, nextTick } from 'vue';
import GLayout from '/@/shared/components/g-layout/index.vue';
import JsBarcode from 'jsbarcode';
/**
 * 文档： https://lindell.me/JsBarcode/
 */
export default defineComponent({
  components: { GLayout },
  data() {
    return {
      field: {
        id: 'test',
        options: {
          width: 2,
          height: 100,
          displayValue: true,
          lineColor: '#000000',
          background: '#ffffff',
          margin: 4,
          format: 'auto',
        },
      },
      fieldModel: null,
    };
  },
  watch: {
    fieldModel() {
      this.buildBarCode();
    },
  },
  mounted() {
    this.buildBarCode();
  },
  methods: {
    buildBarCode() {
      nextTick(() => {
        JsBarcode(`#${this.field.id}`).init();
      });
    },
  },
});
